package com.zzyl.controller.security;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.zzyl.base.PageBean;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.RoleDto;
import com.zzyl.entity.Resource;
import com.zzyl.service.ResourceService;
import com.zzyl.service.RoleService;
import com.zzyl.vo.RoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import java.time.LocalDateTime;

@Api(tags = "角色管理")
@RestController
@RequestMapping("/role")
@RequiredArgsConstructor
public class RoleController {
    private final RoleService roleService;
    @PutMapping
    @ApiOperation(value = "角色添加")
    public ResponseResult<?> insert(@RequestBody(required = false) RoleDto roleDto) {
        roleService.insert(roleDto);
        return ResponseResult.success();
    }

    @PatchMapping
    @ApiOperation(value = "角色修改")
    public ResponseResult<?> uodateRole(@RequestBody(required = false) RoleDto roleDto) {
        roleService.uodateRole(roleDto);
        return ResponseResult.success();
    }
    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation(value = "角色分页")
    @Validated
    public ResponseResult<PageBean<RoleVo>> queryRolePage(@PathVariable @Min(value =1)Integer pageNum, @PathVariable @Min(value =1)Integer pageSize, @RequestBody RoleDto roleDto){
        PageBean<RoleVo> list  = roleService.queryRolePage(pageNum,pageSize,roleDto);
        return ResponseResult.success(list);
    }
}
